package com.five.monkey.feign.consumer.client;

import com.five.monkey.feign.consumer.client.fallback.UserFeignClientFallback;
import com.five.monkey.vo.CommonVo;
import com.five.monkey.vo.PageVo;
import com.five.monkey.vo.UserVo;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @author 狻猊
 * @date 2021/8/10 下午5:43
 */
@FeignClient(value = "feign-provider", path = "/provider/user", fallback = UserFeignClientFallback.class)
public interface UserFeignClient {

    @GetMapping(value = "/login", consumes = "application/json")
    CommonVo<UserVo> login(@RequestParam("name") String name, @RequestParam("password") String password);

    @GetMapping(value = "/find/by/{id}", consumes = "application/json")
    CommonVo<UserVo> findById(@PathVariable("id") Long id);

    @PostMapping(value = "/save/to/elasticsearch", consumes = "application/json")
    CommonVo<UserVo> saveToElasticsearch(@RequestBody UserVo userVo);

    @GetMapping(value = "/find/by/{id}/elasticsearch", consumes = "application/json")
    CommonVo<UserVo> findByIdFromElasticsearch(@PathVariable("id") Long id);

    @DeleteMapping(value = "/delete/by/{id}/elasticsearch", consumes = "application/json")
    CommonVo<Boolean> deleteByIdFromElasticsearch(@PathVariable("id") Long id);

    @GetMapping(value = "/find/all/elasticsearch", consumes = "application/json")
    CommonVo<List<UserVo>> findAllFromElasticsearch();

    @GetMapping(value = "/page/by/{status}/elasticsearch", consumes = "application/json")
    CommonVo<PageVo<UserVo>> pageByStatusFromElasticsearch(@PathVariable("status") Integer status, @RequestParam(value = "page") int page,
                                                           @RequestParam(value = "size", required = false, defaultValue = "10") int size);

    @GetMapping(value = "/list/by/{status}/elasticsearch", consumes = "application/json")
    CommonVo<List<UserVo>> listByStatusFromElasticsearch(@PathVariable("status") Integer status);
}
